local desc_xlkj_mode = [[
  # 修罗抗金简介
  ___

  军八4个玩家（身份固定为主忠，玩家不足人机补位）对抗4个阴间人机（身份固定为反贼，体力和体力上限+2）

  胜利条件：反贼全部阵亡。

  失败条件：主忠全部阵亡。

  修罗神礼：每轮开始，每个玩家从3选1选项中选择并执行其效果。(主忠人数大于反贼人数或者主忠人数小于3且等于反贼人数，无修罗神礼奖励。)

]]
-- local XlkjObj = require "packages/xlkj/XlkjObj"
local U = require "packages/utility/utility"

--开启测试
local IStest = false
--开启测试AI武将
local IStestAI = false
--强力武将
local strongGens = {"l__zhurong","l__xunyu","l__luxun","huangwudie","godzhenji","ty__caochun","ty__xushao","js__liubei","js__sunjian","mobile__guozhao","zhangfen","mobile__wenyang","caoxian","wm__zhugeliang","mobile__caomao","js__wangrongh","godguojia","mobile__duyu","l__zhangliao","ty__xujing"}
--新强力武将
local newstrongGens = {"olmou__yuanshao","ol__pengyang","olz__xunchen","olz__xunyou","olz__zhongyan","ol__feiyi","ol__fengfangnv","wolongfengchu","caoxiancaohua","ol__panshu"}
-- newstrongGens = {"ol__fengfangnv","ol__fengfangnv","ol__fengfangnv","ol__fengfangnv","ol__fengfangnv"}
--将广技能池
local jiangguangSkills = {
  wei={"ex__jianxiong","ex__fankui","ex__ganglie","ex__qingjian","jiushi","ex__tuxi","ex__luoyi","ex__luoshen","xunxun","chengxiang","jianmie",
  "ol_ex__miji","ol_ex__shebian","ol_ex__jushou","ol_ex__jieming","quhu","ol_ex__duanliang","bolong","weikui","lizhan","ol__jingce","benyu",
  "benyu","yawang","gushe","chouce","weijing","ol__wanwei","jixian","saodi","zengou","huanfu","gongjie","tousui","ex__yiji","os__kaiji"},

  shu={"ex__rende","ex__yijue","os__zhibian","ex__guanxing","yajiao","ex__tieji","jianyan","jijie","m_ex__fangquan","m_ex__tiaoxin","ol_ex__liegong","mini__kuanggu",
  "ol_ex__huoji","ol_ex__lianhuan","ol_ex__xuanhuo","zhanding","zhuri","ol__xuehen","ol__sanyao","fengpo","ziyuan","bingzheng","shuimeng","jianji","dianjun",
  "hongji","os_ex__lieren","os__jimeng","os__shuaiyan","os__jieyu"},

  wu={"ex__zhiheng","os__fenghan","fenwei","gongxin","keji","kurou","ex__yingzi","ex__fanjian","ex__guose","ex__qianxun","ex__jieyin","ol_ex__zhiyan","zhijian","ol_ex__guzheng",
  "ol_ex__ganlu","ol_ex__zhiyan","bizheng","duwu","jinzhi","yingjian","anjian","os_ex__gongqi","os__fenwu","os__shangyi","anxu","ty_ex__xingxue","mou__tieji"},

  qun={"qingnang","os_xing__zhilue","liyu","ol_ex__jianchu","ex__biyue","lijian","ty_ex__qiaomeng","ty__kuangfu","ol_ex__beige","m_ex__luanji","ol_ex__mieji","ol_ex__qieting",
  "zhidao","lianzhu","tunjiang","liejie","jianman","kenshang","langdao","shandao","yichengl","hunjiang","guixin","os__dingfa","os__moukui","os__yimou","os__juchen","shelie",
  "os__daoji","os__daigui","os__weipo","os__jiange","os__xuechang"},
}
--强将技能池
local qiangjiangSkills = {
  wei={"qingguo","ty__wangxi","ol_ex__renxin","ol_ex__chengxiang","luoying","ol_ex__jiangchi","ol_ex__zhenlie","ol_ex__shensu","ol_ex__jiewei","ol_ex__qiangxi",
  "xieshu","ol__qingxian","ol__caishi","tuifeng","qingzhong","ol__yuejian","zhangjiq","kanpod","gengzhan","qingyix","xiangxu","os__shepan","os__zhongzuo","os__zhanyi",
  "os__yuanhu","xiace"},

  shu={"ol_ex__kanpo","os__yuyan","ol_ex__changbiao","ol_ex__enyuan","ex__longdan","yirong","weilingy","duoshou","ol__huxiao","ol__qirang","ol__yuhua","yuxu",
  "sheyan","juanxia","kangrui","zhenying","yanru","jilis","longyin","os_ex__xuhe","os_ex__qianxi","os__qingkou","os__zhiming"},

  wu={"ol_ex__tianxiang","ol_ex__fenji","tianyi","ol_ex__wulie","ol_ex__dimeng","ol_ex__jiang","ol_ex__zhijian","ol_ex__buyi","ol__dulie","shenxing","aocai","lixia","dingpan",
  "weiyi","xianbi","cangxin","runwei","ol__fengyan","suji","chanshuang","heji","guanwei","os_ex__shenxing","os__congji","xiaoji","ol_ex__lihuo","os__yilie","ty__songshu","ty_ex__danshou"},

  qun={"ol_ex__leiji","fuyuanx","ol_ex__shuangxiong","ol_ex__luanwu","ol_ex__zishou","anyong","os__cuijin","os__zhuidu","os__beini","os__fupan","os__qingtao","os__jiekuang","os__kujian",
  "ol__zhuiji","ol__shichou","ol__zhendu","ol__niluan","xiying","wenji","fuji","gangzhi","neifa","yuanzi","liantao","pingduan","renxia","os__gongge","os__cairu","os__xiawang","os__zhenhu",
  "ty__huoshui"
  },
}
--队友人机将池
local friendsRobots = {"ol__zhugedan","zhangyao","ol_ex__dongzhuo","liuzan","mou__machao","mxing__huangzhong","mxing__zhoubuyi","mobile__yanxiang","gongsunkang","maojie","peixiu","qianzhao","mobile__yanghu",
"mobile__gaolan","m_ex__wuguotai","m_ex__xusheng","m_ex__liaohua","m_ex__zhuhuan","quyi","caoying","ol__huangzu","ol__bianfuren","ol__yanghu","qinghegongzhu","weizi",
"dengzhong","luoxian","tianchou","ol_sp__sunce","ol__zhugejin","olz__wangling","olz__wuqiao","olmou__jiangwei","olmou__taishici","ol_ex__weiyan","ol_ex__dianwei",
"ol_ex__wolong","ol_ex__pangtong","ol_ex__taishici","ol_ex__pangde","ol_ex__yanliangwenchou","ol_ex__xuhuang","ol_ex__menghuo","ol_ex__sunjian","ol_ex__jiangwei",
"ol_ex__zhangzhaozhanghong","ol_ex__jianyong","ty__lidian","panjun","lvdai","ty__xiahouba","jianggan","ty__liuqi","liubian","ty__liuyu",
"liangxing","zhangheng","shamoke","ty__xugong","mushun","sunlang","ty__guanyu","ty__zhangning","ty__hansui","ty__zhujun","ty__dingyuan",
"ty__miheng","ty__huaxin","ty__xunchen","mu__caiwenji","ty__panfeng","lukai","wuanguo","sunli","ty_ex__gaoshun","ty_ex__guohuai","ty_ex__guanping","ty_ex__zhangsong","ty_ex__sunluban",
"ty_ex__jvshou","ty_ex__sunxiu","ty_ex__zhuzhi","ty_ex__taishici","js__machao","l__lvbu","l__sunshangxiang","l__guanyu","miniex__yuanshao","mou__xiahoushi","os_ex__madai",
"os_ex__caoxiu","os__fuwan","liwei","os__jiakui","xuyou","haozhao","zhugezhan","maliang"
} 
--玩家将池
local playerGens = {"guandu__hanmeng","qiaoxuan","caoyi","tystar__zhangchunhua","tystar__dongzhuo","js__zhangliao","js__chendeng","js__chunyuqiong","js__xuyou","js__sunce","js__luxun","js__nanhualaoxian","js__dongbai","js__xushao","js__huangfusong",
"zhoubuyi","yuanji","ty_ex__lingtong","ty_ex__wangyi","ty_ex__zhuran","ty_ex__wuyi","chenshi","tystar__caoren","ty__yangyi","zhoushan","caomao","chentai","olmou__jiangwei",
"caoshuang","luotong","chengjiw","ty__huangzu","ol__huangzu","m_ex__liru","mu__daqiao","mu__miheng","mu__xiaoqiao","gongsunxiu","mengyou","gongsundu","ty__zhangmancheng","zhangchu","peiyuanshao","liupi","tangji","niufu","dongxie","ty__zhangchangpu",
"fengfang","ty__niujin","ty__mifangfushiren","ty__zhaoyan","wangwei","liyixiejing","sunhuan","ty__mengda","shiyi","dufuren","qinyilu","bianxi","ty__huban","ty__hujinding","guannings","ty__nanhualaoxian","ty__tongyuan",
"ty__pangdegong","ty_ex__zhangsong","ty_ex__caorui","ty_ex__caoxiu","ty_ex__xunyou","ty_ex__guohuanghou","ty_ex__taishici","ty_ex__gongsunzan","ty__sunluyu","zhaoyanw","zhangxuan","ty__sunru","xiahoulingnv","pangshanmin","zhanghu","lvlingqi",
"liuyong","wanniangongzhu","panghui","ty__zhaotongzhaoguang","yuantanyuanshangyuanxi","yuechen","ty__jiaxu","ty__chendeng","caimaozhangyun","ty__gaolan","yinfuren","ty__lvkuanglvxiang",
"chengui","chenjiao","qinlang","ty__dongzhao","ty__tangzi","ty__lifeng","xianglang","furongfuqian","ty__huojun","ty__wuban","ty__yanghu","luyusheng","wupu","zhenghun",
"ty__sunhanhua","wanglie","dongwan","ty__qiaorui","ty__yuejiu","sunchen","ty__sunziliufang","ty__wangrongh","ty__caosong","ty__dongcheng","caoanmin",
"yanfuren","yanrou","tymou__jvshou","tymou__zhangxiu","tymou__guanping","tymou__caoshuang","tymou__simashi","tymou__lusu","ty__huangfusong","ty__wangjun","simahui","ty__puyuan",
"gexuan","wufan","zhaozhi","zhaoang","huanfan","xizheng","malingli","duanqiaoxiao","ty__ruiji","ty__huaman","xielingyu","dingfuren","quanhuijie","ganfurenmifuren",
"ty_sp__zhenji","fanyufeng","ruanyu","ty__panshu","ty__fengfangnv","caohua","liutan","ty__luotong","ty__yangbiao","ruanji","dongguiren","ty__tengfanglan",
"zhangjinyun","zhugejing","ty__chenlin","ty__tengfanglan","ty__tengfanglan","ty__yangwan","guanyueg","js__yangbiao","js__zhanghe","miniex__machao","miniex__huangyueying","mou__lvmeng",
"os__tianyu","niufudongxie","os__guanqiujian","os_sp__caocao","bingyuan","wenchou","mobile__wangyuanji","mobile__yanghuiyu"}
--修罗对抗武将
local battleToGens = {"wm_guanyu","baiqi","godzhangjiao","ty__liuye","caojinyu","tenggongzhu","guozhao","ty__sunyi","godganning","zerong","hulao2__godlvbu","zhouyi","dukui","ty__wangchang","hulao3__godlvbu","caofang"}
-- battleToGens = {"baiqi","baiqi","baiqi","baiqi","baiqi"}
--玩家测试武将
local TESTgen = "mouxusheng"
--测试AI武将（避免自由选）
local TESTgens = {"guozhao","m_ex__liaohua","zhangfen","xielingyu","zhouyi","ol__tengfanglan","dongyun","l__zhangliao","ex__simayi","ol_ex__zhangjiao","ty_ex__zhuran","l__lvbu","ty__yanghu","zhaotongzhaoguang","miniex__huangyueying","ty__yanghu","godzhaoyun","js__guanyu","lvlingqi","dukui","ty_ex__wuyi","ol_ex__sunjian","xizhicai","qinmi","godganning","ty__chenlin","ex__ganning","yuejiu","caomao","ty__lidian","ol__luyusheng","godganning","ty_ex__caozhi","zhaotongzhaoguang"}
--过滤其他卡组（只允许白名单的卡组加入牌堆）
local WHILEcards = {"standard","standard_cards","maneuvering","lang_cards","tenyear_token","mobile_derived","ol_token","overseas_token"}
--保留玩家本模式重要的标记
-- local SAVEmarks = {"curlayerphase","@slash_dmg","@trick_dmg","@pdlbox","@gold_num","@df_lingxin","@shieldnum","@slash_num"}

--初始化游戏对象
-- local initGameObj = function(player)
--   --初始化游戏数据
--   local initGameData = {

--   }
-- end

local xlkj_getLogic = function()
  local xlkj_logic = GameLogic:subclass("xlkj_logic")

  function xlkj_logic:initialize(room)
    GameLogic.initialize(self, room)
    -- for k,skills in pairs(qiangjiangSkills) do
    --   for _,ski in ipairs(skills) do
    --     local fkskills = Fk.skills
    --     if not fkskills[ski] then
    --       p(ski)
    --       dbg()
    --     end
    --   end
    -- end
    self.role_table = {
      { "lord" },
      { "lord", "rebel" },
      { "lord", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "loyalist", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "loyalist" },
    }
  end

  function xlkj_logic:prepareForStart()
    local room = self.room
    local players = room.players
    self:addTriggerSkill(GameRule)
    for _, trig in ipairs(Fk.global_trigger) do
      if trig.name ~= "mobile_effect" then  --关闭手杀特效
        self:addTriggerSkill(trig)
      end
    end
    self.room:sendLog{ type = "$GameStart" }
    room:setBanner("@[:]xlkjbaner_rule","xlkj-intro")
  end

  function xlkj_logic:prepareDrawPile()
    local room = self.room
    --重新过滤卡组
    local filterCardIds = {}
    -- local saveCardIds = {}
    local excepts = {"lightning"} -- 删除一些卡组
    local allCardIds = Fk:getAllCardIds()
    for i = 1, #allCardIds do
      local id = allCardIds[i]
      local card = Fk:getCardById(id)
      if card then
        if card.is_derived then
          table.insert(room.void, id)
          room:setCardArea(id, Card.Void, nil)
        else
          if table.contains(WHILEcards,card.package.name) then
            if not table.contains(excepts,card.trueName) then
              table.insert(filterCardIds,id)
              -- table.insert(saveCardIds,id)
            end
          end
        end
      end
    end
    table.shuffle(filterCardIds)
    room.draw_pile = filterCardIds
    -- room.totalcards = saveCardIds
    for _, id in ipairs(room.draw_pile) do
      room:setCardArea(id, Card.DrawPile, nil)
    end
  end

  function xlkj_logic:assignRoles()
    local room = self.room
    local n = #room.players
    local roles = self.role_table[n]
    table.shuffle(roles)
    local bots_t = {}
    local players_t = {}
    for i = 1, n do
      local p = room.players[i]
      if p.id < 0 then
        table.insert(bots_t,{p.id,i})
      else
        table.insert(players_t,{p.id,i})
      end
    end
    local randplayer = room.players[table.random(players_t)[2]]
    randplayer.role = "lord"
    randplayer.role_shown = true
    room:broadcastProperty(randplayer, "role")

    local rebles = 4
    for i = 1, n do
      local p = room.players[i]
      if p.role ~= "lord" then
        if p.id < 0 and rebles > 0 then
          p.role = "rebel"
          rebles = rebles - 1
        else
          p.role = "loyalist"
        end
        p.role_shown = true
        room:broadcastProperty(p,"role")
      end
    end
  end

  function xlkj_logic:chooseGenerals()
    local room = self.room
    local lord = room:getLord()
    room.current = lord

    local generalNum = 5
    local repcount = 4
    local generals = table.random(playerGens,50) 
    local extragens = table.random(strongGens,4)
    local extranewgens = table.random(newstrongGens,4)
    local friendgens = table.random(friendsRobots,10)

    local command = "MiniGame"
    local game_type = "seeothersel"
    local game = Fk.mini_games[game_type]
    if not game then return end

    local realplayers = {}
    local enemyrobots = {}
    local players = room.players
    local beatenemys = table.random(battleToGens,#battleToGens)
    for _,pr in ipairs(players) do
      if pr.id > 0 then
        local data = {seat = pr.seat.."号",repcount = repcount,repgens = {},gens ={table.remove(extragens,1),table.remove(extranewgens,1)},othergens = {},otherseats={}}
        for i = 1,generalNum do
          local gen = table.remove(generals,1)
          table.insert(data.gens,gen)
        end
        for i = 1,repcount do
          local gen = table.remove(generals,1)
          table.insert(data.repgens,gen)
        end
        if pr.role == "lord" and IStest then
          table.insert(data.gens,1,"mouxusheng")
        end
        pr.mini_game_data = { type = game_type, data = data }
        table.insert(realplayers,pr)
      else
        if pr.role == "rebel" then
          table.insert(enemyrobots,pr)
        else
          pr.default_reply = json.encode(table.remove(friendgens,1)) --忠臣人机将池
        end
      end     
    end
    --反贼人机将池
    local erobots = table.random(enemyrobots,4)
    for i,pr in ipairs(erobots) do
      if i <= #realplayers then
        pr.stronggen = #realplayers < 3 and true or false 
        pr.default_reply = json.encode(table.remove(beatenemys,1))
      else
        pr.default_reply = json.encode(table.remove(friendgens,1))
      end
    end

    for _,pr in ipairs(realplayers) do
      if pr.id > 0 and pr.mini_game_data then
        if #realplayers == 1 then
          -- table.insert(pr.mini_game_data.data.othergens,pr.mini_game_data.data.gens)
          -- table.insert(pr.mini_game_data.data.othergens,pr.mini_game_data.data.gens)
          -- table.insert(pr.mini_game_data.data.othergens,pr.mini_game_data.data.gens)
          pr.request_data = json.encode(pr.mini_game_data)
          pr.default_reply = game.default_choice and json.encode(game.default_choice(pr, pr.mini_game_data.data)) or ""
        else
          for i, friend in ipairs(realplayers) do
            if pr ~= friend and friend.id > 0 and friend.mini_game_data then
              table.insert(pr.mini_game_data.data.othergens,friend.mini_game_data.data.gens)
              table.insert(pr.mini_game_data.data.otherseats,friend.mini_game_data.data.seat)
            end
          end
          pr.request_data = json.encode(pr.mini_game_data)
          pr.default_reply = game.default_choice and json.encode(game.default_choice(pr, pr.mini_game_data.data)) or ""
        end
      end
    end

    room:notifyMoveFocus(realplayers, "AskForGeneral")
    room:doBroadcastRequest(command, realplayers)

    for _, p in ipairs(players) do
      p.mini_game_data = nil
      if not p.reply_ready then
        p.client_reply = p.default_reply
        p.reply_ready = true
      end
    end

    -- room:askForChooseKingdom(realplayers)
    for _, pr in ipairs(players) do
      if pr.general == "" and pr.reply_ready then
        -- p(pr.client_reply)
        -- dbg()
        local general = json.decode(pr.client_reply)
        room:setPlayerGeneral(pr, general,true)
      else
        room:setPlayerGeneral(pr, "blank_shibing",true)
      end
      -- room:broadcastProperty(pr, "general")
      pr.default_reply = ""
    end
    room:askForChooseKingdom(players)
    for _, p in ipairs(players) do
      room:broadcastProperty(p, "general")
      room:broadcastProperty(p, "kingdom")
    end
  end
  return xlkj_logic
end

---------------------------------------技能--------------------------------------------
local bingduo = fk.CreateTriggerSkill{
  name = 'bingduoSkill',
  -- anim_type = "negative",
  priority = 10,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill,fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      return player == target and self == data
    else
      return player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      room:drawCards(player, GensLimts:getKJBuffCfg()[room.settings.gameMode][self.name],self.name)
    else
      room:handleAddLoseSkills(player,"-"..self.name,nil,false)
    end  
  end,
}
local bingduoMaxMod = fk.CreateMaxCardsSkill{
  name = "#bingduoMaxMod",
  frequency = Skill.Compulsory,
  correct_func = function (self, player)
    if player:hasSkill(self) then
      return -1
    end
  end,
}
bingduo:addRelatedSkill(bingduoMaxMod)
Fk:addSkill(bingduo)
Fk:loadTranslationTable{
  ["bingduoSkill"] = "兵多",
  [":bingduoSkill"] = "锁定技，获得此技能时你摸x张牌，回合内手牌上限-1，每轮结束失去此技能（x由模式决定：修罗抗金为4，普通抗金为3）",
  ["#bingduoMaxMod"] = "兵多",
}

local jiangguang = fk.CreateTriggerSkill{
  name = 'jiangguangSkill',
  -- anim_type = "negative",
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill,fk.AfterSkillEffect,fk.RoundEnd,fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return player == target and self == data
    elseif event == fk.AfterSkillEffect then
      return player == target and player:getMark("skillonce") ~= 0 and table.contains(player:getMark("skillonce"),data.name)
    else
      return player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      local kingdomskills = table.clone(jiangguangSkills[player.kingdom] or jiangguangSkills["qun"])
      local ret = {}
      local n = 4
      while n > 0 and #kingdomskills > 0 do
        local i = math.random(1, #kingdomskills)
        -- local revskill = table.remove(kingdomskills, i)
        if not player:hasSkill(kingdomskills[i]) then
          table.insert(ret,table.remove(kingdomskills, i))
          n = n - 1
        end        
      end
      local chs = room:askForChoices(player,ret,2,2,self.name,self.name,false,true)
      local translate = table.map(chs,function(ch) return Fk:translate(ch) end)
      translate = table.concat(translate,"、")
      room:doBroadcastNotify("ShowToast","<font color='red'><b>"..Fk:translate(player.general).."</b></font>".."通过".."<font color='green'><b>"..Fk:translate(self.name).."</b></font>".."获得了".."<font color='purple'><b>"..translate.."</b></font>")
      room:setPlayerMark(player,"skillonce",chs)
      chs = table.concat(chs,"|")
      room:handleAddLoseSkills(player,chs,nil,false)
    elseif event == fk.AfterSkillEffect then
      local mark = player:getMark("skillonce")
      table.removeOne(mark,data.name)
      room:handleAddLoseSkills(player,"-"..data.name,nil,false)
      if #mark == 0 then
        room:setPlayerMark(player,"skillonce",0)
        room:handleAddLoseSkills(player,"-"..self.name,nil,false)
      else
        room:setPlayerMark(player,"skillonce",mark)
      end
    else
      if player.norlosejg then player.norlosejg = nil return end
      local mark = player:getMark("skillonce")
      local losestr = ""
      if event == fk.RoundEnd then
        losestr = "-"..self.name.."|"
        player.norlosejg = true
      end
      if mark ~= 0 and #mark > 0 then
        for _,ski in ipairs(mark) do
          losestr = losestr.."-"..ski.."|"
        end
      end
      room:handleAddLoseSkills(player,losestr,nil,false)
    end  
  end,
}
Fk:addSkill(jiangguang)
Fk:loadTranslationTable{
  ["jiangguangSkill"] = "将广",
  [":jiangguangSkill"] = "你可以从4个和你同势力的武将技能选2个技能获得，当因此获得的技能生效后失去该技能。（如果有未触发技能则每轮结束失去这些技能）",
}

local kuangwang = fk.CreateTriggerSkill{
  name = 'kuangwangSkill',
  -- anim_type = "negative",
  priority = 12,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill,fk.RoundEnd,fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      return player == target and self == data
    else
      return player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local value = GensLimts:getKJBuffCfg()[room.settings.gameMode][self.name]
    if event == fk.EventAcquireSkill then
      player.maxHp = player.maxHp + value
      player.hp = player.hp + value
      room:setPlayerProperty(player, "maxHp", player.maxHp)
      room:setPlayerProperty(player, "hp", player.hp)      
    elseif event == fk.RoundEnd then
      room:changeMaxHp(player,-(value-1))
      room:handleAddLoseSkills(player,"-"..self.name,nil,false)
    else
      local judge = {
        who = player,
        reason = "lightning",
        pattern = ".|2~9|spade",
      }
      room:judge(judge)
      if judge.card.suit == Card.Spade and judge.card.number > 1 and judge.card.number < 10 then
        room:damage{
          to = player,
          damage = 3,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
    end  
  end,
}
Fk:addSkill(kuangwang)
Fk:loadTranslationTable{
  ["kuangwangSkill"] = "狂妄",
  [":kuangwangSkill"] = "锁定技，你获得此技能后，体力和体力上限+x。每个回合开始你进行一次闪电判定。每轮结束你失去此技能且体力上限-(x-1)（x由模式决定：修罗抗金为3，普通抗金为2）",
}

local tri_yongjin = fk.CreateTriggerSkill{
  name = 'tri_yongjinSkill',
  -- anim_type = "negative",
  priority = 13,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local value = GensLimts:getKJBuffCfg()[room.settings.gameMode][self.name]
    for i = 1, value, 1 do
      if #room:canMoveCardInBoard() == 0 or player.dead then break end
      local to = room:askForChooseToMoveCardInBoard(player, "#jufeng-choose:::", self.name, true, nil, false)
      if #to == 2 then
        local result = room:askForMoveCardInBoard(player, room:getPlayerById(to[1]), room:getPlayerById(to[2]), self.name, nil, nil)
        if not result then
          break
        end
      else
        break
      end
    end
    -- local yongjin = Fk.skills["ex__yongjin"]    
    -- local effect = {from=player.id}
    -- yongjin.onUse(yongjin, room, effect) 
    -- room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(tri_yongjin)
Fk:loadTranslationTable{
  ["tri_yongjinSkill"] = "飓风",
  ["#jufeng-choose"] = "飓风：你可以移动场上 %arg 张牌",
  [":tri_yongjinSkill"] = "你可以移动场上的牌。",
}

local tri_shenfen = fk.CreateTriggerSkill{
  name = 'tri_shenfenSkill',
  -- anim_type = "negative",
  priority = 14,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local indicateids,damtars = {},{}
    local value = GensLimts:getKJBuffCfg()[room.settings.gameMode][self.name]
    for _,pr in ipairs(room:getOtherPlayers(player)) do
      if not GensLimts:isSameCamp(player,pr) then
        table.insert(indicateids,pr.id)
        table.insert(damtars,pr)
      end
    end
    if value == "half" then
      indicateids = table.random(indicateids,math.ceil(#indicateids/2))
      damtars = table.map(indicateids,function(pid) return room:getPlayerById(pid) end)
    end
    room:doIndicate(player.id, indicateids)
    table.forEach(damtars, function(p)
      if not p.dead then room:damage{ from = player, to = p, damage = 1,damageType=fk.FireDamage, skillName = self.name } end
    end)
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(tri_shenfen)
Fk:loadTranslationTable{
  ["tri_shenfenSkill"] = "流星",
  [":tri_shenfenSkill"] = "其他随机x名与你不同阵营的角色受到1点火属性伤害。（x由模式决定：修罗抗金为所有与你不同阵营角色数，普通抗金同理但为半数）",
}

local jingbing = fk.CreateTriggerSkill{
  name = 'jingbingSkill',
  -- anim_type = "negative",
  priority = 15,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local allCardIds = {}
    table.insertTable(allCardIds,room.draw_pile)
    table.insertTable(allCardIds,room.discard_pile)
    for i = 1,2 do
      local cardType = i       
      local allCardMapper = {}
      local allCardNames = {}
      for _, id in ipairs(allCardIds) do
        local card = Fk:getCardById(id)
        if card.type == cardType then
          if allCardMapper[card.name] == nil then
            table.insert(allCardNames, card.name)
          end    
          allCardMapper[card.name] = allCardMapper[card.name] or {}
          table.insert(allCardMapper[card.name], id)
        end
      end  
      if #allCardNames == 0 then return end
      local cardName = room:askForChoice(player, allCardNames, self.name)
      local toGain -- = room:printCard(cardName, Card.Heart, 1)
      if #allCardMapper[cardName] > 0 then
        toGain = allCardMapper[cardName][math.random(1, #allCardMapper[cardName])]
        room:obtainCard(player.id, toGain, true, fk.ReasonPrey)
      end       
    end  
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(jingbing)
Fk:loadTranslationTable{
  ["jingbingSkill"] = "精兵",
  [":jingbingSkill"] = "你可以从牌堆的所有牌名中分别选择获得【基本牌】、【锦囊牌】各一张。",
}


local qiangjiang = fk.CreateTriggerSkill{
  name = 'qiangjiangSkill',
  -- anim_type = "negative",
  priority = 16,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill,fk.RoundEnd,fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return player == target and self == data
    else
      return player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventAcquireSkill then
      local kingdomskills = table.clone(qiangjiangSkills[player.kingdom] or qiangjiangSkills.qun)
      local ret = {}
      local n = GensLimts:getKJBuffCfg()[room.settings.gameMode][self.name]
      while n > 0 and #kingdomskills > 0 do
        local i = math.random(1, #kingdomskills)
        -- local revskill = table.remove(kingdomskills, i)
        if not player:hasSkill(kingdomskills[i]) then
          table.insert(ret,table.remove(kingdomskills, i))
          n = n - 1
        end        
      end
      local chs = room:askForChoices(player,ret,1,1,self.name,self.name,false,true)
      chs = chs[1]
      room:doBroadcastNotify("ShowToast","<font color='red'><b>"..Fk:translate(player.general).."</b></font>".."通过".."<font color='green'><b>"..Fk:translate(self.name).."</b></font>".."获得了".."<font color='purple'><b>"..Fk:translate(chs).."</b></font>")
      room:setPlayerMark(player,"skillround",chs)
      room:handleAddLoseSkills(player,chs,nil,false)
    else
      if player.norloseqj then player.norloseqj = nil return end
      local losestr = ""
      if event == fk.RoundEnd then
        losestr = "-"..self.name.."|"
        player.norloseqj = true
      end
      local mark = player:getMark("skillround")
      if mark ~= 0 then
        losestr = losestr.."-"..mark.."|"
      end
      room:handleAddLoseSkills(player,losestr,nil,false)
    end  
  end,
}
Fk:addSkill(qiangjiang)
Fk:loadTranslationTable{
  ["qiangjiangSkill"] = "强将",
  [":qiangjiangSkill"] = "锁定技，你获得此技能后，从x个和你同势力的武将技能选1个技能获得，每轮结束失去此技能（包含获得的技能,x由模式决定：修罗抗金为4，普通抗金为3）",
}

local shenyu = fk.CreateTriggerSkill{
  name = 'shenyuSkill',
  -- anim_type = "negative",
  priority = 17,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tars = {}
    for _,pr in ipairs(room.alive_players) do
      if pr ~= player then
        table.insert(tars,pr.id)
      end
    end
    if #tars > 0 then
      tars = room:askForChoosePlayers(player,tars,1,1,"#shenyuSkill_choose",self.name,true)
      if tars and #tars > 0 then
        local tar = room:getPlayerById(tars[1])
        room:swapSeat(player,tar)
      end
    end
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(shenyu)
Fk:loadTranslationTable{
  ["shenyuSkill"] = "换位",
  ["#shenyuSkill_choose"] = "你选择一名其他角色与其互换位置",
  -- ["rechp1"] = "回复1点体力并摸1张牌",
  -- ["losemaxrec2"] = "失去1点体力上限并回复2点体力",
  [":shenyuSkill"] = "你选择一名其他角色与其互换位置",
}

local rongzhuang = fk.CreateTriggerSkill{
  name = 'rongzhuangSkill',
  -- anim_type = "negative",
  priority = 18,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local rongzhuangnum = player.rongzhuangnum or 2
    local searchnum = rongzhuangnum * 3
    local rongzhuangcount = 0
    local equipMap = {}
    local findequips = function(roompile,equipmap,count,num,needemptyslot)
      for _, id in ipairs(roompile) do
        local card = Fk:getCardById(id)
        local sub_type = card.sub_type
        if card.type == Card.TypeEquip and not table.contains(player.sealedSlots,Util.convertSubtypeAndEquipSlot(sub_type)) and (needemptyslot and (not player:getEquipment(sub_type)) or true) then
          local list = equipmap[tostring(sub_type)] or {}
          table.insert(list, id)
          equipmap[tostring(sub_type)] = list
          count = count + 1
          if count >= num then
            break
          end
        end
      end
    end
    findequips(room.draw_pile,equipMap,rongzhuangcount,searchnum,true)
    if rongzhuangcount < searchnum then
      findequips(room.discard_pile,equipMap,rongzhuangcount,searchnum,true)
      if rongzhuangcount < searchnum then
        local lastpile = #room.draw_pile > #room.discard_pile and room.draw_pile or room.discard_pile
        findequips(lastpile,equipMap,rongzhuangcount,searchnum)
      end
    end
    local put = U.getRandomCards(equipMap, rongzhuangnum)
    if #put > 0 then
      U.moveCardIntoEquip(room, player, put, self.name, true, player)
    end
    player.rongzhuangnum = nil
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(rongzhuang)
Fk:loadTranslationTable{
  ["rongzhuangSkill"] = "戎装",
  [":rongzhuangSkill"] = "你从牌堆中随机检索两张不同类别的装备牌置入你的装备区。",
}

local mori = fk.CreateTriggerSkill{
  name = 'moriSkill',
  -- anim_type = "negative",
  priority = 19,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local indicateids,damtars = {},{}
    for _,pr in ipairs(room:getOtherPlayers(player)) do
      if not GensLimts:isSameCamp(player,pr) then
        table.insert(indicateids,pr.id)
        table.insert(damtars,pr)
      end
    end
    local value = GensLimts:getKJBuffCfg()[room.settings.gameMode][self.name]
    if value == "half" then
      indicateids = table.random(indicateids,math.ceil(#indicateids/2))
      damtars = table.map(indicateids,function(pid) return room:getPlayerById(pid) end)
    end
    room:doIndicate(player.id, indicateids)
    table.forEach(damtars, function(p)
      room:loseHp(p,1,self.name)
    end)
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(mori)
Fk:loadTranslationTable{
  ["moriSkill"] = "落日",
  [":moriSkill"] = "与你不同阵营的x名角色流失1点体力。（x由模式决定：修罗抗金为所有与你不同阵营角色数，普通抗金同理但为半数）",
}

local zhongzhan = fk.CreateTriggerSkill{
  name = 'zhongzhanSkill',
  -- anim_type = "negative",
  priority = 20,
  -- frequency = Skill.Compulsory,
  events = {fk.TurnStart,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player == target and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if fk.TurnStart == event then 
      if room:askForSkillInvoke(player, self.name) then
        return true
      else
        room:handleAddLoseSkills(player,"-"..self.name,nil,false)
        return false
      end
    else
      if player:getMark("noanylimit-turn") ~= 0 then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if fk.TurnStart == event then
      room:setPlayerMark(player,"noanylimit-turn",1)
      if player.maxHp > 1 then
        local num = player.maxHp - 1
        room:changeMaxHp(player,-num)
        room:drawCards(player,num,self.name)
      end
    else
      room:setPlayerMark(player,"noanylimit-turn",0)
      room:killPlayer({ who = player.id })
    end
  end,
}
local zhongzhan_nummod = fk.CreateTargetModSkill{
  name = "#zhongzhan_nummod",
  -- frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope)
    return player:hasSkill(zhongzhan) and player:getMark("noanylimit-turn") == 1
  end,
}
local zhongzhan_dismod = fk.CreateTargetModSkill{
  name = "#zhongzhan_dismod",
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill(zhongzhan) and player:getMark("noanylimit-turn") == 1
  end,
}
zhongzhan:addRelatedSkill(zhongzhan_nummod)
zhongzhan:addRelatedSkill(zhongzhan_dismod)
Fk:addSkill(zhongzhan)
Fk:loadTranslationTable{
  ["zhongzhanSkill"] = "终战",
  ["#zhongzhan_nummod"] = "终战",
  ["#zhongzhan_dismod"] = "终战",
  [":zhongzhanSkill"] = "你的回合开始，若你发动此技能你的体力上限变为1，然后你摸损失的体力上限的牌数且本回合内你使用牌没有距离与次数限制，回合结束你死亡。若不发动失去此技能",
}

local shayi = fk.CreateTriggerSkill{
  name = 'shayiSkill',
  -- anim_type = "negative",
  priority = 21,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
local shayi_extramod = fk.CreateTargetModSkill{
  name = "#shayi_extramod",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill("shayiSkill") and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return GensLimts:getKJBuffCfg()[Fk:currentRoom().room_settings.gameMode]["shayiSkill"]
    end
  end,
}
shayi:addRelatedSkill(shayi_extramod)
Fk:addSkill(shayi)
Fk:loadTranslationTable{
  ["shayiSkill"] = "杀意",
  ["#shayi_extramod"] = "杀意",
  [":shayiSkill"] = "锁定技，你的出牌阶段额外使用x张杀。回合结束失去此技能。（x由模式决定：修罗抗金为3，普通抗金为2）",
}

local yilao = fk.CreateTriggerSkill{
  name = 'yilaoSkill',
  -- anim_type = "negative",
  priority = 22,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
    player:gainAnExtraTurn(true,self.name)
  end,
}
Fk:addSkill(yilao)
Fk:loadTranslationTable{
  ["yilaoSkill"] = "逸劳",
  [":yilaoSkill"] = "你获得1个额外的回合",
}

local yunshi = fk.CreateTriggerSkill{
  name = 'yunshiSkill',
  -- anim_type = "negative",
  priority = 23,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local indicateids,targets = {},{}
    for _,pr in ipairs(room.alive_players) do
      if not GensLimts:isSameCamp(player,pr) then
        table.insert(indicateids,pr.id)
      end
    end
    indicateids = table.random(indicateids,math.ceil(#indicateids/2))
    targets = table.map(indicateids,function(pid) return room:getPlayerById(pid) end)
    room:doIndicate(player.id, indicateids)
    table.forEach(targets, function(p)
      if not p.dead then
        room:askForDiscard(p, 2, 2, true, self.name, false)
      end
    end)
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(yunshi)
Fk:loadTranslationTable{
  ["yunshiSkill"] = "陨石",
  [":yunshiSkill"] = "与你不同阵营的角色（随机取一半角色数）丢弃2张牌",
}
--点兵
local dianbing = fk.CreateTriggerSkill{
  name = 'dianbingSkill',
  -- anim_type = "negative",
  priority = 24,
  frequency = Skill.Compulsory,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return player == target and self == data
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local allCardIds = {}
    table.insertTable(allCardIds,room.draw_pile)
    -- table.insertTable(allCardIds,room.discard_pile)

    local cardType = room:askForChoice(player, {"basic", "trick", "equip"}, self.name)   
    local cardtypemap = {basic=1,trick=2,equip=3}  
    local allCardMapper = {}
    local allCardNames = {}
    for _, id in ipairs(allCardIds) do
      local card = Fk:getCardById(id)
      if card.type == cardtypemap[cardType] then
        if allCardMapper[card.name] == nil then
          table.insert(allCardNames, card.name)
        end    
        allCardMapper[card.name] = allCardMapper[card.name] or {}
        table.insert(allCardMapper[card.name], id)
      end
    end  
    if #allCardNames == 0 then return end
    local cardName = room:askForChoice(player, allCardNames, self.name)
    local toGain -- = room:printCard(cardName, Card.Heart, 1)
    if #allCardMapper[cardName] > 0 then
      toGain = allCardMapper[cardName][math.random(1, #allCardMapper[cardName])]
      room:obtainCard(player.id, toGain, true, fk.ReasonPrey)
    end 
    room:handleAddLoseSkills(player,"-"..self.name,nil,false)
  end,
}
Fk:addSkill(dianbing)
Fk:loadTranslationTable{
  ["dianbingSkill"] = "点兵",
  [":dianbingSkill"] = "你从基本，锦囊，装备牌类型中选择一项。再从此类型的所有牌名里选一张卡获得。",
}
---------------------------------------技能--------------------------------------------


--修罗抗金模式
local xlkj_rule = fk.CreateTriggerSkill{
  name = "#xlkj_rule",
  priority = 0.001,
  refresh_events = {fk.RoundStart,fk.GameOverJudge,fk.GameStart},
  can_refresh = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player.role == "lord"
    elseif event == fk.GameOverJudge then
      return player == target
    else
      return player.id < 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      room:setTag("SkipGameRule", true)
      local players,playercamps,enemycamps = {},{},{}
      local lord = room:getLord()
      for _,pr in ipairs(room.alive_players) do
        if pr.id > 0 then
          table.insert(players,pr)
          -- room:handleAddLoseSkills(player,"hunjiang",nil,false)
        end
        if GensLimts:isSameCamp(pr,lord) then
          table.insert(playercamps,pr.id)
        else
          table.insert(enemycamps,pr.id)
        end
      end
      if #players > 4 then
        room:doBroadcastNotify("ShowToast", "游戏玩家不能超过四人，游戏结束")
        return room:gameOver("rebel")
      elseif #players > 1 then
        room:setTag("SkipNormalDeathProcess", true)
      end
      if #playercamps > #enemycamps or (#playercamps < 3 and #playercamps == #enemycamps) then return room:doBroadcastNotify("ShowToast", "主忠人数大于反贼或者主忠人数小于3且等于反贼人数。无修罗神礼奖励。") end
      local getbuff = table.clone(GensLimts:getKJRandBuffs()[room.settings.gameMode])
      if room:getTag("RoundCount") > 1 then
        table.insert(getbuff,"zhongzhanSkill")
      end
      -- getbuff = {"shayiSkill","shayiSkill","shayiSkill"}
      table.shuffle(getbuff)
      for _, p in ipairs(players) do
        local choices = {}
        for i =1,3 do
          if #getbuff > 0 then
            table.insert(choices,table.remove(getbuff,1))
          end        
        end      
        p.request_data = json.encode({ choices, choices, "#roundchc", "#roundchc", true })      
      end
    
      room:notifyMoveFocus(players, "AskForChoice")
      room:doBroadcastRequest("AskForChoice", players)
      local yilao_pid
      local selchcinfo = {}
      for i, pr in ipairs(players) do
        if pr.client_reply == "yilaoSkill" and i ~= #players then
          yilao_pid = pr.id
        else
          table.insert(selchcinfo,{id=pr.id,chs=pr.client_reply})
        end
      end
      if yilao_pid then
        table.insert(selchcinfo,{id=yilao_pid,chs="yilaoSkill"})
      end
      for _, info in ipairs(selchcinfo) do
        local pr = room:getPlayerById(info.id)
        room:handleAddLoseSkills(pr,info.chs,nil,false)
      end
    elseif event == fk.GameOverJudge then
      local tar = room:getPlayerById(data.who)
      local onlyenemy = table.every(room.alive_players,function(pr) return not GensLimts:isSameCamp(pr,tar) end)
      if not onlyenemy then return end
      local victoryrole = tar.role == "rebel" and "lord" or "rebel"
      room:gameOver(victoryrole)
    else
      local upmaxhp_func = function(pr,v)
        pr.maxHp = pr.maxHp + v
        pr.hp = pr.hp + v
        room:setPlayerProperty(pr, "maxHp", pr.maxHp)
        room:setPlayerProperty(pr, "hp", pr.hp) 
      end
      room:handleAddLoseSkills(player,"ex__yingzi",nil,false)
      if player.role == "rebel" then
        -- room:handleAddLoseSkills(player,"l_feiyang|l_bahu",nil,false)
        upmaxhp_func(player,not player.stronggen and 2 or 1)
      end
    end
  end,
}
Fk:addSkill(xlkj_rule)

local xlkj_mode = fk.CreateGameMode{
  name = "xlkj_mode",
  minPlayer = 8,
  maxPlayer = 8,
  rule = xlkj_rule,
  logic = xlkj_getLogic,
  whitelist = table.clone(WHILEcards),
  winner_getter = function(self, victim)
    local room = victim.room
    local alive = table.filter(room.alive_players, function(p)
      return not p.surrendered
    end)
    if #alive ~= 1 then return "" end
    return alive[1].role
  end,
  surrender_func = function(self, playedTime)
    local surrenderJudge = { { text = "time limitation: 10s", passed = playedTime >= 10 } }
    -- if Self.role ~= "lord" then
      table.insert(surrenderJudge, { text = "1v1: left you alive", passed = true})
    -- end
    return surrenderJudge
  end,
}

Fk:addMiniGame{
  name = "seeothersel",
  qml_path = "packages/lang/qml/AllPlayersSelGenBox",
  default_choice = function(player, data)
    return data.gens[1]
  end,
  update_func = function(player, data)
    local room = player.room
    -- p(data)
    -- dbg()
    -- local d = player.mini_game_data.data
    for _,pr in ipairs(room.players) do
      if pr.id > 0 and pr ~= player and pr.mini_game_data then
        -- local friend = pr
        pr:doNotify("UpdateMiniGame", json.encode(data))
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["xlkj_mode"] = "修罗抗金",
  ["#xlkj_rule"] = "修罗抗金",
  ["@[:]xlkjbaner_rule"] = "抗金",

  ["xlkj-intro"]="介绍",
  [":xlkj-intro"]= desc_xlkj_mode,

  ["#roundchc"] = "先登制敌",

  [":xlkj_mode"] = desc_xlkj_mode,
}

return xlkj_mode
